package com.gxa.controller;

import com.gxa.pojo.Userinfo;
import com.gxa.service.impl.UserinfoServiceImpl;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "用户信息管理")
public class UserinfoController {

    @Autowired
    private UserinfoServiceImpl userinfoService;


    @PostMapping("/userinfo")
    @ApiOperation("用户信息管理添加")
    @ResponseBody
    public ResponseData insertUserinfo(@RequestBody Userinfo userinfo) {

        if (userinfoService.insertUserinfo(userinfo)) {
            return new ResponseData(1, "添加成功");
        } else {
            return new ResponseData(0, "添加失败");
        }
    }
    /**
     * 添加数据
     *
     * @param userinfo 主键
     * @return 添加是否成功
     */
    //@DeleteMapping("/add")
   // @Insert("/insert")
    @GetMapping("/selectUserinfo")
    @ApiOperation(value = "用户信息管理查找",httpMethod = "POST")
  /*  public ResponseData selectUserinfo(Userinfo userinfo) {
        ResponseData responseData = new ResponseData();
        if (this.userinfoService.selectUserinfo(userinfo)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }*/
    public ResponseData selectUserinfo(@ApiParam(value = "显示第几页",required = true) Integer pageNum, @ApiParam(value = "每页显示几条",required = true) Integer pageSize){

        if(userinfoService.selectUserinfo(pageNum,pageSize)!=null){
            return new ResponseData(1,"显示成功",userinfoService.selectUserinfo(pageNum,pageSize));
        }else {
            return new ResponseData(0,"显示失败");
        }
    }
    @DeleteMapping("/deleteUserinfo")
    @ApiOperation("用户信息删除")
    @ResponseBody
    public ResponseData deleteUserinfo(@ApiParam(value = "要删除的名字",required = true) String userinfo_name ){
        if(userinfoService.deleteUserinfo(userinfo_name)){
            return new ResponseData(1,"删除成功");
        }else {
            return new ResponseData(0,"删除失败");
        }
    }
}
